package com.zhenyi.youqu.adminShop.index;

import java.util.Date;

import com.cjw.model.DBMap;
import com.utils.AESUtils;
import com.youqu.common.model.YqOrder;
import com.youqu.common.model.YqShopUser;
import com.zhenyi.youqu.core.YQController;

public class ShopController extends YQController {

	private final String AES_KEY = "youqu!@#$%^&*()-";

	/**
	 * 登录接口
	 */
	public void auth() {
		// String shop = getPara("shop");
		// String mobile = getPara("mobile");
		String account = getPara("account");
		String password = getPara("password");

		// YqShop shopInfo = YqShop.dao.searchFirst("name", shop);
		// if (shopInfo == null) {
		// renderFailure(404, "商户不存在");
		// return;
		// }
		password = AESUtils.decrypt(AES_KEY, password);
		if (password == null) {
			renderFailure(500, "解密失败,请重试");
			return;
		}

		DBMap map = new DBMap();
		// map.put("shopId", shopInfo.getId());
		// map.put("mobile", mobile);
		map.put("account", account);
		map.put("password", password);
		YqShopUser user = YqShopUser.dao.searchFirst(map);
		if (user == null) {
			renderFailure(500, "账号/密码错误");
			return;
		}
		if (user.getShopId() == null) {
			renderFailure(500, "请登录商户账户");
			return;
		}
		user.setLoginTime(new Date());
		user.update();
		user.put("shop", YqOrder.LONG_HASHID.encode(user.getShopId()));
		renderSuccess(user);
	}

	/**
	 * 登录页面
	 */
	public void login() {
	}

	/**
	 * 支付页面
	 */
	@Override
	public void index() {
		super.index();
	}

	/**
	 * 提交支付申请
	 */
	@Override
	public void submit() {
		super.submit();
	}

	/**
	 * 订单列表
	 */
	public void order() {
	}

	/**
	 * 订单详情
	 */
	public void orderInfo() {
	}
}
